<?php $this->load->view('Pre/common/header.html');?>
<script type="text/javascript" src="<?php echo base_url('common/home')?>/js/memberInfo.js"></script>

<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.Msg.js"></script>
<!--付款页面 begin-->
<div class="memberPage">
    <h1>确认订单信息</h1>

    <!--发货地址 begin-->
    <div class="memberBar sendAddressInfo">
        <div class="memberTitle">
            <div class="memberTitleTxt">发货地址</div>
            <div class="memberTitleUp"></div>
        </div>

        <div class="memberCon">
            <ul>
                <?php foreach($customer_add_list as $customer_additem):?>
                <li class="order_region defaultAddress<?php echo $customer_additem->customer_region_id==$orderModel->customer_region_id?" selectedAddress":""?>">
                    <div class="sendName"><?php echo $customer_additem->c_name?></div>
                    <div class="sendMobile"><?php echo $customer_additem->phone?></div>
                    <div class="sendAddress">
                        <?php echo $customer_additem->province?>  <?php echo $customer_additem->city?>  <?php echo $customer_additem->county?>
                        <?php echo $customer_additem->detailed_add?>
                    </div>
                    <span style="margin-right:30px;" onclick="update_region(<?php echo $customer_additem->customer_region_id?>)">修改</span>
                    <span onclick="delete_region(<?php echo $customer_additem->customer_region_id?>)">删除</span>
                    <span style="left:20px;width:72px;" onclick="set_mail_add('<?php echo $customer_additem->customer_region_id?>',this)">设置邮寄地址</span>
                    <?php if($customer_additem->is_default==1):?>
                    <div class="default" style="font-weight:700;">默认收货地址</div>
                    <?php else:?>
                    <div class="default" style="cursor:pointer;" onclick="setdefault(<?php echo $customer_additem->customer_region_id?>)">设置默认收货地址</div>
                    <?php endif;?>
                </li>
                <?php endforeach;?>
                <li class="last">
                    <br />
                    <br />
                    <br />
                    +<br />
                    添加新地址
                </li>
            </ul>

            <div class="moreAddress">显示更多发货地址</div>
        </div>
    </div>
    <script type="text/javascript">
        function Success(data, index) {
            layer.close(index);
            $.Success(data);
        }
        function _Success(data) {
            $.Success(data);
        }
        $(function () {
            $(".last").click(function () {
                layer.open({
                    type: 2,
                    title: false,
                    maxmin: false,
                    shadeClose: false, //开启点击遮罩关闭层
                    area: ['794px', '645px'],
                    offset: ['100px', ''],
                    closeBtn: 0,
                    content: '<?php echo site_url('customer/add_region/'.$customer_id.'/'.$orderModel->goods_order_id)?>' + '?backurl=' + window.location.href
                });
            });
        })

        function setdefault(cr_id) {
            var seturl = "<?php echo site_url('customer/set_default')?>";
            var backurl = window.location.href;
            $.post(seturl, { 'cr_id': cr_id, 'backurl': backurl }, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    _Success(jsonData);
                } else {
                    _Success(jsonData);
                }
            });
        }


        function update_region(cr_id) {
            layer.open({
                type: 2,
                title: false,
                maxmin: false,
                shadeClose: false, //开启点击遮罩关闭层
                area: ['794px', '645px'],
                offset: ['100px', ''],
                closeBtn: 0,
                content: '<?php echo site_url('customer/update_region')?>?cr_id=' + cr_id + '&backurl=' + window.location.href
            });
        }

        function delete_region(cr_id) {
            var url = '<?php echo site_url('customer/delete_region')?>?cr_id=' + cr_id;
            $.post(url, { 'back_url': window.location.href }, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    $.Success(jsonData);
                } else {
                    $.Success(jsonData);
                }
            });
        }
    </script>
    <!--发货地址 end-->
    <!--我的订单 begin-->
    <form method="post" action="<?php echo site_url('order/order_to_pay')?>">
        <div class="confirmOrder">
            <div class="tableTitle">
                <div class="w320">商品</div>
                <div class="w270">属性</div>
                <div class="w140">单价（元）</div>
                <div class="w140">数量</div>
                <div class="w140">小计（元）</div>
                <div class="w188">操作</div>
            </div>

            <div class="orderBar">
                <div class="w320">
                    <a href="<?php echo site_url('goods/details/'.$orderModel->goods_id)?>">
                        <img src="<?php echo base_url().$orderModel->thumbnail_img?>" width="55" height="79" alt="" />
                        <div class="proName">
                            <?php echo $orderModel->goodstitle?><br />
                            订单号： <?php echo $orderModel->order_code?>
                        </div>
                    </a>
                </div>
                <div class="w270">
                    颜色分类：<?php echo $orderModel->colortitle?><br />
                    尺码：<?php echo $orderModel->sizetitle?><br />
                    风格：<?php echo $orderModel->styletitle?><br />

                </div>
                <div class="w140 orderr_price" shop_price="<?php echo $orderModel->shop_price?>">￥<?php echo $orderModel->shop_price?></div>
                <div class="w140"><span onclick="reduce_count('<?php echo $orderModel->goods_order_id?>')" class="minus">-</span><input readonly="readonly" class="order_count" type="text" value="<?php echo $orderModel->count?>" /><span onclick="add_count('<?php echo $orderModel->goods_order_id?>')" class="add">+</span></div>
                <div class="w140 littleCount">￥<?php echo $orderModel->shop_price*$orderModel->count?></div>
                <div class="w188"><span onclick="del_order('<?php echo $orderModel->goods_order_id?>')">删除</span></div>

                <script type="text/javascript">
                    function del_order(order_id) {
                        var backurl = window.location.href;
                        var r_customer_url = "<?php echo site_url('customer/index')?>";
                        var url = '<?php echo site_url('order/del_order')?>';
                        $.post(url, { 'order_id': order_id, 'backurl': window.location.href, 'customer_page_url': r_customer_url }, function (data) {
                            var jsonData = $.parseJSON(data);
                            if (jsonData.Statu == 'ok') {
                                $.Success(jsonData);
                            } else {
                                $.Success(jsonData);
                            }
                        });
                    }
                    function format_money(price) {
                        return Math.floor(parseFloat(price * 100)) / 100;
                    }
                    function add_count(order_id) {
                        var old_val = parseInt($(".order_count").val());
                        var new_val = old_val + 1;

                        var url = '<?php echo site_url('order/update_order_count')?>';
                        var backurl = window.location.href;
                        $.post(url, { 'orderid': order_id, 'new_val': new_val, 'backurl': backurl }, function (data) {
                            var jsonData = $.parseJSON(data);
                            if (jsonData.Statu == 'ok') {
                                $(".order_count").val(new_val);
                                var shop_price = format_money($('.orderr_price').attr('shop_price'));
                                var talprice = shop_price * parseInt(new_val);
                                $('.littleCount').text('￥' + talprice);
                                $('.order_tal_price').text('￥' + talprice);
                                $.Success(jsonData);
                            } else {
                                $.Success(jsonData);
                            }
                        });
                    }
                    function reduce_count(order_id) {
                        var old_val = parseInt($(".order_count").val());
                        var new_val = 1;
                        if (old_val > 1) {
                            new_val = old_val - 1;
                        }
                        if (old_val != new_val) {
                            var url = '<?php echo site_url('order/update_order_count')?>';
                            var backurl = window.location.href;
                            $.post(url, { 'orderid': order_id, 'new_val': new_val, 'backurl': backurl }, function (data) {
                                var jsonData = $.parseJSON(data);
                                if (jsonData.Statu == 'ok') {
                                    $(".order_count").val(new_val);
                                    var shop_price = format_money($('.orderr_price').attr('shop_price'));
                                    var talprice = shop_price * parseInt(new_val);
                                    $('.littleCount').text('￥' + talprice);
                                    $('.order_tal_price').text('￥' + talprice);
                                    $.Success(jsonData);
                                } else {
                                    $.Success(jsonData);
                                }
                            });
                        }
                    }
                    function set_mail_add(region_id, obj) {
                        var orderid = '<?php echo $orderModel->goods_order_id?>';
                        var url = '<?php echo site_url('order/set_mail_add')?>';
                        var backurl = window.location.href;
                        $.post(url, { 'orderid': orderid, 'region_id': region_id, 'backurl': backurl }, function (data) {
                            var jsonData = $.parseJSON(data);
                            if (jsonData.Statu == 'ok') {
                                $(obj).parent('li').siblings().removeClass('selectedAddress');
                                $(obj).parent('li').addClass('selectedAddress');
                                var add = "<span>寄送至：</span>" + jsonData.Data.province + "  " + jsonData.Data.city + "  " + jsonData.Data.county + "   " + jsonData.Data.detailed_add + "";
                                var person_tel = "<span>收货人：</span>" + jsonData.Data.c_name + "  " + (jsonData.Data.phone != null || jsonData.Data.phone != '' ? jsonData.Data.phone : jsonData.Data.tel);
                                $(".person").html(person_tel);
                                $(".address").html(add);
                                $('#order_add_region').val(region_id);
                                $.Success(jsonData);
                            } else {
                                $.Success(jsonData);
                            }
                        });
                    }
                </script>
            </div>

            <!--备注 begin-->
            <div class="remarks">
                <div class="remarksTitle">给卖家留言：</div>
                <textarea name="order_msg" id="order_msg" placeholder="如需定制，请在备注栏写下 身长、胸围、腰围、袖长、袖肥、袖口肥测量方法请参照主页公告栏中的使用指南 如需帮助请联系客服"><?php echo $orderModel->order_msg?></textarea>
                <div class="sendTime">
                    发货时间：卖家承诺在买家付款后，定制产品将于1-2周内<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;制作完成并交付到您手中。
                </div>
            </div>
            <!--备注 end-->
        </div>
        <!--我的订单 end-->
        <!--实付结果 begin-->
        <div class="total">
            
            <div class="totalPrice">实付款：<span class="order_tal_price">￥<?php echo $orderModel->shop_price*$orderModel->count?></span></div>
            <div class="address"><span>寄送至：</span><?php echo $orderModel->province?>  <?php echo $orderModel->city?>  <?php echo $orderModel->county?>   <?php echo $orderModel->detailed_add?></div>
            <div class="person"><span>收货人：</span><?php echo $orderModel->c_name?>  <?php echo !empty($orderModel->phone)?$orderModel->phone:$orderModel->tel?></div>
        </div>
        <!--实付结果 end-->

        <div class="clear"></div>
        <input type="hidden" id="order_add_region" value="<?php echo $orderModel->customer_region_id?>" />
        <input type="hidden" name="goods_order_id" id="goods_order_id" value="<?php echo $orderModel->goods_order_id?>" />
        <input type="hidden" name="backurl" id="backurl" value="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>" />
        <input class="goPay" type="submit" value="去结账" />
        <script type="text/javascript">
            $(function () {
                $('.goPay').click(function () {
                    if ($('#order_add_region').val() == '0') {
                        layer.msg('添加地址并且设置邮寄地址！', { icon: 7 });
                        return false;
                    } else {
                        $(this).submit();
                    }
                });
            });
        </script>
    </form>
</div>
<!--付款页面 end-->
<?php $this->load->view('Pre/common/footer.html');?>
